﻿using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using Silent.WCF.Interfaces;

namespace Silent.WCF.Base
{
    public abstract class ServiceHostBuilderBase
    {
        private ServiceHost m_host;

        public ServiceHost Build(object host, params Uri[] baseAddresses)
        {
            m_host = new ServiceHost(host, baseAddresses);
            AddEndpoints();
            AddBehaviors();
            return m_host;
        }

        protected abstract void AddBehaviors();
        protected abstract void AddEndpoints();

        protected void AddBehavior<T>(T behavior) where T : class, IServiceBehavior
        {
            m_host.Description.Behaviors.Add(behavior);
        }
        protected void AddServiceEndpoint<TService>(Binding binding) where TService : class, IService
        {
            m_host.AddServiceEndpoint(typeof(TService), binding, typeof(TService).ToString());
        }
    }
}